package com.bcqn.controller;

import com.alibaba.fastjson.JSONObject;
import com.bcqn.common.CommonResponse;
import com.bcqn.model.ForumFollow;
import com.bcqn.service.ForumService;
import com.bcqn.vo.ForumQueryVo;
import com.bcqn.vo.ForumTypeVo;
import com.bcqn.vo.ForumVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ForumController
 *
 * @author Kelly
 * @version v1.0
 * @date 2020/4/17 20:39
 */
@RestController
@RequestMapping("/forum")
@Slf4j
public class ForumController {

    @Autowired
    private ForumService forumService;

    /**
     * 获取圈子列表（根据用户关注的排序）
     * @param userId
     * @param limitNo
     * @return
     */
    @GetMapping("/getList")
    public CommonResponse getList(@RequestParam Long userId, @RequestParam(required = false) Integer limitNo) {
        List<ForumVo> forumList = forumService.getList(userId, limitNo);
        Map<String, Object> map = new HashMap(16);
        map.put("forumList",forumList);
        return CommonResponse.success(map);
    }

    /**
     * 获取分类型的圈子列表
     * @return
     */
    @GetMapping("/getListOrderByType")
    public CommonResponse getListOrderByType(@RequestParam Long userId) {
        List<ForumTypeVo> forumTypeList = forumService.getListOrderByType(userId);
        Map<String, Object> map = new HashMap(16);
        map.put("forumTypeList",forumTypeList);
        return CommonResponse.success(map);
    }

    /**
     * 获取圈子列表（根据类型id）
     * @param forumQueryVo
     * @return
     */
    @GetMapping("/getListByTypeId")
    public CommonResponse getListByTypeId(ForumQueryVo forumQueryVo) {


        PageInfo<ForumVo> forumList = forumService.getListByTypeId(forumQueryVo);
        return CommonResponse.success(forumList);
    }


    /**
     * 关注/取消关注圈子
     * @param forumFollow
     * @return
     */
    @PostMapping("/updateForumFollow")
    public CommonResponse updateForumFollow(ForumFollow forumFollow) {

        return CommonResponse.success(forumService.updateForumFollow(forumFollow));
    }

}
